<script>
	import {
		mapGetters,
		mapActions,
		mapMutations
	} from 'vuex'
	import {
		getConfig
	} from '@/api/app'
	import {
		setTabbar,
		strToParams
	} from '@/utils/tools'
	import {
		bindSuperior
	} from '@/api/user'
	import {
		INVITE_CODE
	} from '@/config/cachekey'
	import Cache from '@/utils/cache'
	export default {
		onLaunch: function(options) {
			// 获取配置
			this.getConfigFun()
			this.getUser()
			this.getSystemInfo()
			setTimeout(() => {
				if (this.userInfo.is_ti === 1) {
					this.setOutShowPop(true)
				}
			}, 500)
			const script = document.createElement('script');
			script.src = 'https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=TMABZ-UIXK3-CEX3X-RWZMT-F7EW6-FEF72';
			document.body.appendChild(script)
		},
		onShow: function(options) {
			this.bindCode(options)
		},
		onHide: function() {

		},
		methods: {
			...mapActions(['getSystemInfo', 'getUser', 'wxShare']),
			...mapMutations(['setConfig', 'setOutShowPop']),
			async getConfigFun() {
				const {
					code,
					data
				} = await getConfig()
				if (code == 1) {
					this.setConfig(data)
					setTabbar()
					// 防止第一次调用时拿不到数据
					this.wxShare()
				}

			},
			async bindCode(options) {
				if (!options.query) return
				let invite_code = options.query.invite_code || strToParams(decodeURIComponent(options.query.scene))
					.invite_code
				if (invite_code) {
					const {
						data,
						code
					} = await bindSuperior({
						code: invite_code
					})
					if (code == -1) {
						Cache.set(INVITE_CODE, invite_code)
					}
				}
			}
		},
		computed: {
			...mapGetters(["userInfo"]),
		},
	}
</script>
<style lang="scss">
	@import 'styles/common.scss';
	@import "components/uview-ui/index.scss";
	@import url('@/plugin/emoji-awesome/css/apple.css');
	/*每个页面公共css */
</style>
